package com.loubii.sunshineSchool.ui.avtivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.loubii.sunshineSchool.R;
import com.loubii.sunshineSchool.httpRequest.HttpBin;
import com.loubii.sunshineSchool.pojo.User;
import com.loubii.sunshineSchool.util.ImageUtil;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Response;

public class SSProfileActivity extends BaseActivity {

    @BindView(R.id.headview)
    ImageView headView;
    @BindView(R.id.tv_user_name)
    TextView name;
    @BindView(R.id.real_name)
    TextView real_name;
    @BindView(R.id.real_school)
    TextView school;
    @BindView(R.id.real_id)
    TextView sid;
    @BindView(R.id.bt_send)
    Button send;
    @BindView(R.id.bt_delete)
    Button delete;

    int uid;

    @Override
    protected int getLayoutId() {
        return R.layout.center_detail;
    }

    @Override
    protected void initView() {
        uid = getIntent().getIntExtra("uid", 0);
        HttpBin.userDetail(this, uid, new HttpBin.ResponseListener<User>() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                User user = response.body();
                name.setText(user.getUserName());
                real_name.setText("姓名：" + user.getRealName());
                school.setText("学校：" + user.getSchool());
                sid.setText("学号：" + user.getSid());
                ImageUtil.downloadAvatar(user.getImage(), headView);

            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {

            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.bt_send, R.id.bt_delete})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_delete:
                HttpBin.deleteFriend(this, uid, new HttpBin.ResponseListener<Boolean>() {
                    @Override
                    public void onResponse(Call<Boolean> call, Response<Boolean> response) {
                        if (response.body()) {
                            Toast.makeText(SSProfileActivity.this, "删除成功", Toast.LENGTH_LONG).show();
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            finish();
                        } else {
                            Toast.makeText(SSProfileActivity.this, "不好重复删除哦~", Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    public void onFailure(Call<Boolean> call, Throwable t) {

                    }
                });
                break;
            case R.id.bt_send:
                Intent intent = new Intent(this, SSChatActivity.class);
                intent.putExtra("uid", uid);
                intent.putExtra("name", name.getText());
                startActivity(intent);
                break;
        }
    }
}
